#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi
 

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_ctocd.info <<%EOF%
   cc_rsp_ctocd
   -----------
   Molecule:         HF 
   Wave Function:    CCS, CCSD / 6-31G**
   Test Purpose:     Static nuclear magnetic shielding and 
   		     z-component (in the electric field) of 
		     shielding polarizability in the CTOCD-DZ formalism
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_ctocd.mol <<%EOF%
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    0  Y         1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_ctocd.dal <<%EOF%
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.RPSO
.DIPVEL
.DIPLEN
**WAVE FUNCTIONS
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.CCSD
.THRENR
 1.0d-8
.THRLEQ
 1.0d-8
*CCLR
.OPERAT
YDIPVEL 001RPSOZ
ZDIPVEL 001RPSOY
ZDIPVEL 002RPSOX
XDIPVEL 002RPSOZ
XDIPVEL 003RPSOY
YDIPVEL 003RPSOX
YDIPVEL 004RPSOZ
ZDIPVEL 004RPSOY
ZDIPVEL 005RPSOX
XDIPVEL 005RPSOZ
XDIPVEL 006RPSOY
YDIPVEL 006RPSOX
*CCQR
.OPERAT
ZDIPLEN YDIPVEL 001RPSOZ
ZDIPLEN ZDIPVEL 001RPSOY
ZDIPLEN YDIPVEL 004RPSOZ
ZDIPLEN ZDIPVEL 004RPSOY
ZDIPLEN XDIPVEL 003RPSOY
ZDIPLEN YDIPVEL 003RPSOX
ZDIPLEN XDIPVEL 006RPSOY
ZDIPLEN YDIPVEL 006RPSOX
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_ctocd.check
cat >>cc_rsp_ctocd.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CCSD energies:
CRIT1=`$GREP "Total SCF   energy: * \-100.008919(8|9)." $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * \-100.193662(5|6)." $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy: * \-100.1977909." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=7
ERROR[1]="ENERGIES NOT CORRECT"

# CCS Linear response 
CRIT1=`$GREP  "YDIPVEL .* 001RPSOZ .* -2.26588(0|1).*" $log | wc -l`
CRIT2=`$GREP  "ZDIPVEL .* 001RPSOY .* -2.33442(1|2).*" $log | wc -l`
CRIT3=`$GREP  "ZDIPVEL .* 002RPSOX .*  2.33442(1|2).*" $log | wc -l`
CRIT4=`$GREP  "XDIPVEL .* 002RPSOZ .*  2.26588(0|1).*" $log | wc -l`
CRIT5=`$GREP  "XDIPVEL .* 003RPSOY .*  2.22299(0|1).*" $log | wc -l`
CRIT6=`$GREP  "YDIPVEL .* 003RPSOX .* -2.22299(0|1).*" $log | wc -l`
CRIT7=`$GREP  "YDIPVEL .* 004RPSOZ .*  2.469724.*" $log | wc -l`
CRIT8=`$GREP  "ZDIPVEL .* 004RPSOY .* (\-0|\-).613453.*" $log | wc -l`
CRIT9=`$GREP  "ZDIPVEL .* 005RPSOX .* (0| ).613453.*" $log | wc -l`
CRIT10=`$GREP "XDIPVEL .* 005RPSOZ .* -2.469724.*" $log | wc -l`
CRIT11=`$GREP "XDIPVEL .* 006RPSOY .* (0| ).554066.*" $log | wc -l`
CRIT12=`$GREP "YDIPVEL .* 006RPSOX .* (\-0|\-).554066.*" $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ \
              $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ \
              $CRIT11 \+ $CRIT12`  
CTRL[2]=12
ERROR[2]="CCS LINEAR RESPONSE NOT CORRECT"

# CCS Quadratic response
CRIT1=`$GREP "ZDIPLEN .* YDIPVEL .* 001RPSOZ .*\-44\.6960.*" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN .* ZDIPVEL .* 001RPSOY .* (0| )\.2785.*" $log | wc -l`
CRIT3=`$GREP "ZDIPLEN .* YDIPVEL .* 004RPSOZ .* (\-0|\-)\.70(89|90|91).*" $log | wc -l`
CRIT4=`$GREP "ZDIPLEN .* ZDIPVEL .* 004RPSOY .* (\-0|\-)\.2395.*" $log | wc -l`
CRIT5=`$GREP "ZDIPLEN .* XDIPVEL .* 003RPSOY .* (\-0|\-)\.5405.*" $log | wc -l`
CRIT6=`$GREP "ZDIPLEN .* YDIPVEL .* 003RPSOX .* (0| )\.5405.*" $log | wc -l`
CRIT7=`$GREP "ZDIPLEN .* XDIPVEL .* 006RPSOY .* (0| )\.3467.*" $log | wc -l`
CRIT8=`$GREP "ZDIPLEN .* YDIPVEL .* 006RPSOX .* (\-0|\-)\.3467.*" $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ \
              $CRIT6 \+ $CRIT7 \+ $CRIT8`
CTRL[3]=8
ERROR[3]="CCS QUADRATIC RESPONSE NOT CORRECT"

# CCSD linear response
CRIT1=`$GREP "YDIPVEL .* 001RPSOZ .*  \-1\.3478.*" $log | wc -l`
CRIT2=`$GREP "ZDIPVEL .* 001RPSOY .*  \-2\.5790.*" $log | wc -l`
CRIT3=`$GREP "ZDIPVEL .* 002RPSOX .*   2\.5790.*" $log | wc -l`
CRIT4=`$GREP "XDIPVEL .* 002RPSOZ .*   1\.3478.*" $log | wc -l`
CRIT5=`$GREP "XDIPVEL .* 003RPSOY .*   2\.3727.*" $log | wc -l`
CRIT6=`$GREP "YDIPVEL .* 003RPSOX .*  \-2\.3727.*" $log | wc -l`
CRIT7=`$GREP "YDIPVEL .* 004RPSOZ .*   2\.5806.*" $log | wc -l`
CRIT8=`$GREP "ZDIPVEL .* 004RPSOY .* (\-0|\-)\.70485.*" $log | wc -l`
CRIT9=`$GREP "ZDIPVEL .* 005RPSOX .* (0| )\.70485.*" $log | wc -l`
CRIT10=`$GREP "XDIPVEL .* 005RPSOZ .*  \-2\.5806.*" $log | wc -l`
CRIT11=`$GREP "XDIPVEL .* 006RPSOY .* (0| )\.61774.*" $log | wc -l`
CRIT12=`$GREP "YDIPVEL .* 006RPSOX .* (\-0|\-)\.61774.*" $log | wc -l`
TEST[4]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ \
              $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10 \+ \
              $CRIT11 \+ $CRIT12`  
CTRL[4]=12
ERROR[4]="CCSD LINEAR RESPONSE NOT CORRECT"

# CCSD quadratic response
CRIT1=`$GREP "ZDIPLEN .* YDIPVEL .* 001RPSOZ .*\-41\.2158.*" $log | wc -l`
CRIT2=`$GREP "ZDIPLEN .* ZDIPVEL .* 001RPSOY .* (0| )\.6549(6|7).*" $log | wc -l`
CRIT3=`$GREP "ZDIPLEN .* YDIPVEL .* 004RPSOZ .* (\-0|\-)\.3301.*" $log | wc -l`
CRIT4=`$GREP "ZDIPLEN .* ZDIPVEL .* 004RPSOY .* (\-0|\-)\.5631.*" $log | wc -l`
CRIT5=`$GREP "ZDIPLEN .* XDIPVEL .* 003RPSOY .* (\-0|\-)\.1670.*" $log | wc -l`
CRIT6=`$GREP "ZDIPLEN .* YDIPVEL .* 003RPSOX .* (0| )\.16700.*" $log | wc -l`
CRIT7=`$GREP "ZDIPLEN .* XDIPVEL .* 006RPSOY .* (0| )\.35111.*" $log | wc -l`
CRIT8=`$GREP "ZDIPLEN .* YDIPVEL .* 006RPSOX .* (\-0|\-)\.35111.*" $log | wc -l`
TEST[5]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ \
              $CRIT6 \+ $CRIT7 \+ $CRIT8`
CTRL[5]=8
ERROR[5]="CCSD QUADRATIC RESPONSE NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%

chmod +x cc_rsp_ctocd.check
#######################################################################
